package com.wvmi.gmall.search.thread;

import com.google.common.collect.Sets;
import com.sun.xml.internal.ws.util.CompletedFuture;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 描述:   <br>
 *
 * @author Wuminming <br>
 * 创建时间: 2023-11-29 11:32 <br>
 * <p>
 * Copyright: 2013 - 2023 www.szwcyq.com Inc. All rights reserved. <br>
 * 注意：本内容仅限于深圳市微创云启科技有限公司内部传阅，禁止外泄以及用于其他的商业目的<br>
 */
public class ThreadTest {
    private static ExecutorService executor = new ThreadPoolExecutor(10, 10,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<>(1000), (r)-> new Thread(r,"测试线程池"));
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main启动了");
        // supplyAsync 有返回值
//        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
//            System.out.println(Thread.currentThread().getId() + "启动了");
//            int i = 10 / 2;
//            System.out.println(Thread.currentThread().getName() + "结束了");
//            return i;
//        }, executor);

        // runAsync 无返回值
//        CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
//            System.out.println(Thread.currentThread().getName()+Thread.currentThread().getId() + "启动了");
//            int i = 10 / 2;
//            System.out.println(Thread.currentThread().getName()+Thread.currentThread().getId() + "结束了");
//        }, executor);

        // thenRunAsync,没有获取参数，没有返回结果
//        CompletableFuture<Void> future = CompletableFuture.supplyAsync(() -> {
//            System.out.println(Thread.currentThread().getName() + Thread.currentThread().getId() + "启动了");
//            int i = 10 / 2;
//            System.out.println(Thread.currentThread().getName() + Thread.currentThread().getId() + "结束了");
//            return i;
//        }, executor).thenRunAsync(() -> {
//            System.out.println(Thread.currentThread().getName() + Thread.currentThread().getId() + "启动了");
//            System.out.println(Thread.currentThread().getName() + Thread.currentThread().getId() + "结束了");
//        },executor);

//        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
//            System.out.println(Thread.currentThread().getName() + Thread.currentThread().getId() + "启动了");
//            int i = 10 / 2;
//            System.out.println(Thread.currentThread().getName() + Thread.currentThread().getId() + "结束了");
//            return i;
//        }, executor).thenApplyAsync((i) -> {
//            System.out.println(Thread.currentThread().getName() + Thread.currentThread().getId() + "启动了");
//            System.out.println(i);
//            System.out.println(Thread.currentThread().getName() + Thread.currentThread().getId() + "结束了");
//            return  i * 2;
//        },executor);
//        System.out.println("main结束了……"+future.get());
        Set<String> tmpRules=new HashSet<>(10);
        String[] split = "all".split(",");
        Set<String> r= Sets.newHashSet(split);
        tmpRules.addAll(r);
    }
}
